package com.ruoyi.common.DataConversion.domain;


import com.ruoyi.common.domin.TypeConvertUtils;
import struct.StructClass;
import struct.StructField;

@StructClass

public class DeviceTCP {
    /**
     * 固定头
     */
    @StructField(order = 0)
    public byte[] head = new byte[]{0x44,0x5A,0x57,0x4C};


    /**
     * 类型
     */
    @StructField(order = 1)
    public byte[] address1=new byte[]{0x03};



    /**
     * 类型
     */
    @StructField(order = 2)
    public byte[] lenth=new byte[2];

    /**
     * 类型
     */
    @StructField(order = 3)
    public byte[] uniqueCode=new byte[2];

    /**
     * 类型
     */
    @StructField(order = 4)
    public byte[] address=new byte[2];

    /**
     * 类型
     */
    @StructField(order = 5)
    public byte[] len=new byte[2];

    /**
     * 类型
     */
    @StructField(order = 6)
    public byte[] crc=new byte[2];



    /**
     * 设置唯一码
     * @param uniqueCode
     */
    public void setUniqueCode(String uniqueCode) {
        this.uniqueCode = TypeConvertUtils.stringToBytes(uniqueCode);
    }

//    /**
//     * 设置写入地址
//     * @param address
//     */
//    public void setAddress(String address) {
//        //将地址码补齐为4位，并且反转
//        String addressReverse= TypeConvertUtils.polishAndReverse(address,4);
//        this.address = TypeConvertUtils.stringToBytes(addressReverse);
//    }

    /**
     * 设置读取数据长度
     */
    public void setDataLength(int dataLengthTemp){
        this.lenth=TypeConvertUtils.intToConverseBytes(dataLengthTemp,2);
    }

    /**
     * 设置读取数据长度
     */
    public void setUniqueCode(int uniqueCode){
        this.uniqueCode=TypeConvertUtils.intToConverseBytes(uniqueCode,2);
    }

    public void setAddress(int address) {
        this.address = TypeConvertUtils.intToConverseBytes(address,2);
    }

    public void setLen(int len) {
        this.len = TypeConvertUtils.intToConverseBytes(len,2);
    }

    public void setCrc(int crc) {
        this.crc = TypeConvertUtils.intToConverseBytes(crc,2);
    }
}
